﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DungeonCraft.Engine.Interfaces;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace DungeonCraft.Engine
{
    public class WireframeRenderer : IRenderer
    {
        private Microsoft.Xna.Framework.Graphics.GraphicsDevice GraphicsDevice;
        private SpriteBatch spriteBatch;
        private SpriteManager spriteManager;
        private Camera camera;


        public WireframeRenderer(Microsoft.Xna.Framework.Graphics.GraphicsDevice GraphicsDevice, SpriteManager spriteManager, Camera camera)
        {
            // TODO: Complete member initialization
            this.GraphicsDevice = GraphicsDevice;
            spriteBatch = new SpriteBatch(GraphicsDevice);
            this.spriteManager = spriteManager;
            this.camera = camera;
        }


        public void Start()
        {
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin();
        }

        public void End()
        {
            spriteBatch.End();
        }

        public void DrawSprite(string spriteName, int x, int y, int width, int height, Rectangle sourceRectangle, Color color)
        {
            int targetX = camera.calcDisplayX(x);
            int targetY = camera.calcDisplayY(y);
            int targetWidth = Convert.ToInt32(Math.Floor(width * camera.Zoom));
            int targetHeight = Convert.ToInt32(Math.Floor(height * camera.Zoom));
            Rectangle targetRect = new Rectangle(targetX, targetY, targetWidth, targetHeight);
            spriteBatch.Draw(spriteManager.getSprite(spriteName), targetRect, sourceRectangle, color);           

        }

        public void DrawText(string text, Vector2 position)
        {
            SpriteFont font = spriteManager.getFont("Arial");
            spriteBatch.DrawString(font, text, position, Color.LightGreen, 0, font.MeasureString(text)/ 2, 1.0f, SpriteEffects.None, 0.5f);
        }
    }
}
